import java.io.*;
import java.util.*;

public class Main {
	BufferedReader bf;
	StringTokenizer st;
	StringBuilder sb;
	
	int cases;
	
	public Main() {
		bf = new BufferedReader(new InputStreamReader(System.in));
		sb = new StringBuilder();
	}
	
	public static void main(String[] args) {
		Main main = new Main();
		main.beginProcess();
	}
	
	public void beginProcess() {
		try {
			int n;
			st = new StringTokenizer(bf.readLine());
			cases = Integer.parseInt(st.nextToken());
			
			while(cases != 0) {
				st = new StringTokenizer(bf.readLine());
				n = Integer.parseInt(st.nextToken());
				
				sb.append(getMinimumSteps(n) + "\n");
				
				cases--;
			}
			
			System.out.print(sb);
		}
		catch(Exception ex) {
			System.err.println(ex.toString());
		}
	}
	
	private int getMinimumSteps(int n) {
		if(n == 1) {
			return + 0;
		} else {
			if(n % 2 == 0)
				return getMinimumSteps(n / 2) + 1;
			else
				return Math.min(getMinimumSteps(n - 1), getMinimumSteps(n + 1)) + 1;
		}
	}
	
}